﻿namespace BTS.COMMON
{
    using System;
    using System.Drawing;

    public sealed class TextWatermarkPainter : WatermarkPainter
    {
        private System.Drawing.Font m_Font;
        private Color m_FontColor;
        private string m_WatermarkText;

        public TextWatermarkPainter(string rawImagePath, int alpha, string text) : base(rawImagePath, alpha)
        {
            this.m_FontColor = Color.Orange;
            this.WatermarkText = text;
        }

        protected override bool AddWatermark(Graphics graphics, Bitmap newImage)
        {
            if (!string.IsNullOrEmpty(this.WatermarkText))
            {
                using (SolidBrush brush = new SolidBrush(Color.FromArgb(base.WatermarkAlpha, this.FontColor.R, this.FontColor.G, this.FontColor.B)))
                {
                    PointF point = new PointF();
                    float num = this.Font.Size * this.WatermarkText.Length;
                    point.X = (newImage.Width / 2) - (num / 2f);
                    point.Y = (newImage.Height / 2) - (this.Font.Height / 2);
                    graphics.DrawString(this.WatermarkText, this.Font, brush, point);
                }
            }
            return true;
        }

        public override void Dispose()
        {
            this.Font.Dispose();
            base.Dispose();
        }

        public System.Drawing.Font Font
        {
            get
            {
                if (null == this.m_Font)
                {
                    this.m_Font = new System.Drawing.Font("Arial Black", 60f, FontStyle.Bold, GraphicsUnit.Pixel);
                }
                return this.m_Font;
            }
            set
            {
                this.m_Font = value;
            }
        }

        public Color FontColor
        {
            get
            {
                return this.m_FontColor;
            }
            set
            {
                this.m_FontColor = value;
            }
        }

        public string WatermarkText
        {
            get
            {
                return this.m_WatermarkText;
            }
            set
            {
                this.m_WatermarkText = value;
            }
        }
    }
}

